import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);
import vuexPersist from "vuex-persist";

export default new Vuex.Store({
  state: {
    list: [
      {
        id: 1,
        title: "第五轮核酸检测是捅喉咙不是捅鼻子",
        author: "郑州防疫部",
      },
      {
        id: 2,
        title: "疫苗要抓紧时间打",
        author: "河南防疫部",
      },
      {
        id: 3,
        title: "这个夏天瓜太多了吃不完",
        author: "娱乐圈纪检委",
      },
      {
        id: 4,
        title: "随便写点啥把",
        author: "2010a",
      },
    ],
  },
  mutations: {
    add(state, obj) {
      state.list.push({
        id: state.list.length + 1,
        title: obj.title,
        author: obj.author,
      });
    },
    remove(state, index) {
      state.list.splice(index, 1);
    },
  },
  actions: {},
  modules: {},
  plugins: [
    new vuexPersist({
      storage: window.localStorage,
    }).plugin,
  ],
});
